<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
class Index extends Controller
{
    public function index($name = '张三')
    {
        // phpinfo();
        // die();
    	// var_dump(APP_PATH);
    	
    	//get传参 [http://my.tp5.com/index/index/index/name/lisi]

    	$data = Db::name('test1_result')->find();
    	// p($data);
    	$this->assign('data',$data);
    	$this->assign('name',$name);

    	return $this->fetch();
    	//显示模板                                          
    	
    //     return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_bd568ce7058a1091"></thinkad>';
    }

 //    public function hello($name = 'world')
	// {
	// 	echo "hello:".$name;

	// 	print_r($this->request->param());
	// 	//※老问题!!!
	// }

    public function hello(){
    	$request = Request::instance();
    	echo $request->url();	//获取当前URL地址 不含域名
    	echo "<br/>";
    	echo $this->request->url();	//获取当前URL地址 不含域名
    	echo "<br/>";
    	echo $this->request->bind('user_name','张三');	//动态绑定属性
    	echo "<br/>";
    	echo $this->request->user_name;	//其他控制器中可以直接使用 不如在控制器中 可以
    	echo "<br/>";
    	echo request()->url();	//为了简洁 方便可以使用 函数助手
    	echo "<br/>";
    	/**
    	 * 请求变量信息
    	 */
    	print_r($request->param());
    	//导出所有参数
    	echo "<br/>";
    	echo $request->param('name');
    	echo "<br/>";
    	print_r(input());
    	echo "<br/>";
    	print_r(input('name'));
    	echo "<br/>";
    	/**
    	 * param方法支持变量的过滤和默认值
    	 */
    	echo $request->param('en_name','jake','strtolower');
    	echo "<br/>";
    	/**
    	 * 指定获取参数	http://www.tp5.com/admin/index/hello.zxy?name=1111&en_name=LUXI
    	 */
    	echo "=====================request====================<br/>";
    	echo 'GET参数：';
    	print_r($request->get()); echo "<br/>";
    	echo 'GET参数：name';
    	print_r($request->get('name')); echo "<br/>";
    	echo 'POST参数：name:';
    	print_r($request->post('name')); echo "<br/>";
    	echo "cookie参数：name:";
    	print_r($request->cookie('name')); echo "<br/>";
    	echo '上传文件信息：image:';
    	print_r($request->file('image')); echo "<br/>";

    	
    	echo "=====================input====================<br/>";
    	echo 'GET参数：';
    	print_r(input('get.')); echo "<br/>";
    	echo 'GET参数：name';
    	print_r(input('get.name')); echo "<br/>";
    	echo 'POST参数：name:';
    	print_r(input('post.name')); echo "<br/>";
    	echo "cookie参数：name:";
    	print_r(input('cookie.name')); echo "<br/>";
    	echo '上传文件信息：image:';
    	print_r(input('file.image')); echo "<br/>";

    	echo "=====================request 其他参数====================<br/>";
    	echo '请求方法：' . $request->method() . '<br/>';
    	echo '访问IP:' . $request->ip() . '<br/>';
    	echo '是否AJax请求：' . ($request->isAjax() ? '是' : '否'). '<br/>';
    	echo '当前域名：' .  $request->domain() . '<br/>';
    	echo '当前入口文件：' . $request->baseFile() . '<br/>';
    	echo '包含域名的完全URL地址：' . $request->url(true).'<br/>';
    	echo 'URL地址的参数信息：' . $request->query() . '<br/>';
    	echo '当前URL地址 不含QUERY_STRING' . $request->baseUrl() . '<br/>';
    	echo 'URL地址中的pathinfo信息：' . $request->pathinfo() . '<br/>';
    	echo 'URL地址中的后缀信息' . $request->ext() . '<br/>';


    	echo "=====================request 当前模块/控制器/操作信息====================<br/>";

    	echo '模块：'.$request->module() . '<br/>';
    	echo '控制器：' . $request->controller() . '<br/>';
    	echo '方法' . $request->action() . '<br/>';
    }

    public function json(){
    	$data = ['name'=>'thinkphp','status'=>'1'];
    	// return $data;
    	return json($data,201);
    	// return xml($data);
    }

    public function fet(){
    	$this->assign('name','渲染 模板');
    	return $this->fetch('index/index2');
    }

    public function succ(){
    	$this->success('正确的页面跳转','hello');
    }

	public function today($year='2017',$month='8'){
		echo "今天是 $year 年 $month 月";
	}

	public function url(){
		echo Url::build('url2','a=1&b=2');
		
		echo "<br/>";
		
		echo url('url2','a=1&b=2');
		
		echo "<br/>";
		
		echo url('url2',['a'=>'1','b'=>'2']);

		echo "<br/>";

		echo url('url2',array('a'=>'1','b'=>'2'));

		echo "<br/>";

		echo url('admin/index2/url2','a=1&b=2');

		echo "<br/>";

		echo url('admin/HelloWorld/hello');		//自动转换 url_convert

		echo "<br/>";

		echo url('tody/2017/07');		//路由规则

		echo "<br/>";
	}

	public function sqlTest(){
        $result = Db::table('test1_result')->limit(0,10)->select();
        //db('test1_result')->limit(0,10)->select();
	    p($result);
    }

}

